package com.ouken.tool;


import com.ouken.com.R;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RoomlistAdapter extends BaseAdapter {
	Context context;  
    String[] contents; //formate is (OK,OK,name,state,active,limit,passwd,name,state,active,limit,passwd)
    
	public RoomlistAdapter(Context context,String[] contents) {
		this.context=context;  
        this.contents=contents;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return (contents.length - 2)/5;  
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return contents[5*position + 2]+" "+contents[5*position + 1 + 2]+" "+contents[5*position + 2 + 2]+" "+
		       contents[5*position + 3 + 2] +" "+ contents[5*position + 4 + 2];  
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;  
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView==null){  
            LayoutInflater inflater=LayoutInflater.from(context);  
            convertView=inflater.inflate(R.layout.roomlist_item, null);  
        }  
        TextView t_name=(TextView)convertView.findViewById(R.id.adapter_roomlist_tv_name);  
        TextView t_state=(TextView)convertView.findViewById(R.id.adapter_roomlist_tv_state);  
        TextView t_mem=(TextView)convertView.findViewById(R.id.adapter_roomlist_tv_mem);  
        
        t_name.setText(contents[5*position + 2]);  
        t_name.setTextColor(Color.BLACK);  
        t_name.setTextSize(20);  
          
        t_state.setText(contents[5*position + 1 + 2].toString().equals("0")?"waiting":"playing");  
        String a = contents[5*position + 1 + 2].toString();
        if(t_state.getText().toString().equals("waiting"))
        {
        	t_state.setTextColor(Color.RED); 
        }else{
        	t_state.setTextColor(Color.GREEN); 
        }
         
        t_state.setTextSize(20);  
        
        t_mem.setText(contents[5*position + 2 + 2]+"/"+contents[5*position + 3 + 2]);  
        t_mem.setTextColor(Color.BLUE);  
        t_mem.setTextSize(20);  
        return convertView;  
	}

}
